package com.thug.engine;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.Manifold;


public class MyContactListener implements ContactListener {
	
	private final SceneManager mSceneMgr;
	
	public MyContactListener(final SceneManager sceneManager) {
		mSceneMgr = sceneManager;
	}

	@Override
	public void beginContact(Contact contact) {
		
		Body bodyA = contact.getFixtureA().getBody();
		Body bodyB = contact.getFixtureB().getBody();
		
		BaseGameEntity obj1 = (BaseGameEntity) bodyA.getUserData();
		BaseGameEntity obj2 = (BaseGameEntity) bodyB.getUserData();
		
		Vector2 normal = contact.getWorldManifold().getNormal();
		Vector2[] points = contact.getWorldManifold().getPoints();
		
		if ((obj1 != null) && (obj2 != null)) {
			obj1.beginContact(bodyA, bodyB, normal, points);
			obj2.beginContact(bodyA, bodyB, normal, points);
		}
		
		//Log.d("Contact Beg A: ", obj1.getType().toString());
		//Log.d("Contact Beg B: ", obj2.getType().toString());
	}

	@Override
	public void endContact(Contact contact) {
		Body bodyA = contact.getFixtureA().getBody();
		Body bodyB = contact.getFixtureB().getBody();
		
		BaseGameEntity obj1 = (BaseGameEntity) bodyA.getUserData();
		BaseGameEntity obj2 = (BaseGameEntity) bodyB.getUserData();
		
		Vector2 normal = contact.getWorldManifold().getNormal();
		Vector2[] points = contact.getWorldManifold().getPoints();
		
		if ((obj1 != null) && (obj2 != null)) {
			obj1.endContact(bodyA, bodyB, normal, points);
			obj2.endContact(bodyA, bodyB, normal, points);
		}
		//Log.d("Contact End A: ", obj1.getType().toString());
		//Log.d("Contact End B: ", obj2.getType().toString());
	}

	@Override
	public void preSolve(Contact contact, Manifold oldManifold) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postSolve(Contact contact, ContactImpulse impulse) {
		// TODO Auto-generated method stub
		
	}

}
